home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 151-175 / scopedisk165 / splitfile / splitfile.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  3KB  |  78 lines

  1. /**************************************************************************
  2. *
  3. *                           SplitFile
  4. *
  5. *                            Written
  6. *                      By Thomas C. DeVeau
  7. *                       November 11, 1990
  8. *
  9. *                     This is Public Domain
  10. **************************************************************************/
  11. #include <libraries/dosextens.h>
  12.  
  13. #define BUFFSIZE 256                /* buffer size */
  14. #define MAXSPLITSIZE 51200L         /* max splitfile size - easier editing */
  15.  
  16. void main(argc,argv)
  17. int argc;
  18. char *argv[];
  19. {
  20.     struct FileHandle *fh1, *fh2, *Open();           /* file handles */
  21.     int size1, size2, nfcnt = 0, pathok = 0;
  22.     char buffer[BUFFSIZE],nfbuf[BUFFSIZE];  /* buffer holds command line filename */
  23.                                             /* nfbuf holds splitfile names */
  24.     char dir[80];                           /* path */
  25.  
  26.     switch(argc)
  27.     {
  28.         case 1:
  29.             printf("Usage: SplitFile <file> [TO <path>]\n");
  30.             exit(1);
  31.         case 2:
  32.             break;
  33.         case 3:
  34.             printf("SplitFile Error: Invalid Path specification.\n");
  35.             exit(1);
  36.         case 4:
  37.             strcpy(&dir[0],argv[3]);
  38.             pathok = 1;
  39.             break;
  40.         default:
  41.             exit(1);
  42.     }
  43.     fh1 = Open(argv[1],MODE_OLDFILE);       /* open the original file */
  44.     if(fh1 == 0)                            /* if won't open, show error */
  45.     {
  46.         printf("File \"%s\": Not Found.\n",argv[1]);
  47.         exit(1);
  48.     }
  49.  
  50.     for(;;)                                 /* loop forever until broken */
  51.     {
  52.         if(pathok)          /* get splitfile name */
  53.             sprintf(&nfbuf[0],"%s%s.sf%d",dir,argv[1],nfcnt);
  54.         else
  55.             sprintf(&nfbuf[0],"%s.sf%d",argv[1],nfcnt);
  56.         fh2 = Open(&nfbuf[0],MODE_NEWFILE);         /* open splitfile */
  57.         size1 = size2 = 0;
  58.         printf("Writing to file: %s\n",nfbuf);
  59.         while(size1 < MAXSPLITSIZE)           /* check for splitfile size */
  60.         {
  61.             size2 = Read(fh1,buffer,BUFFSIZE); /* read from original file */
  62.             Write(fh2,buffer,size2);           /* write to splitfile */
  63.             if(size2 < BUFFSIZE)
  64.                 goto endit;      /* if read less than needed, end program */
  65.             size1 += size2;      /* add sizes to get max size */
  66.         }
  67.         Close(fh2);              /* close the splitfile */
  68.         nfcnt++;                 /* increment splitfile count */
  69.     }
  70. endit:
  71.     if(fh2) Close(fh2);          /* if splitfile open, close it */
  72.     Close(fh1);                  /* close original file */
  73.     exit(1);                     /* end of program */
  74. }
  75.  
  76.  
  77.  
  78.